/*******************************************************************************
 * Copyright (c) 2005, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/**
 * 
 */
package us.gaaoc.framework.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import us.gaaoc.framework.model.CaseRecord;
import us.gaaoc.framework.model.CourtHearingNegotiationStatus;
import us.gaaoc.framework.model.CourtHearingNegotiations;

/**
 * 
 * @author hea
 * @date Apr 17, 2006
 * @version: GAJE 1.5
 * 
 */
public class CourtHearingNegotiationsDAOHibernate
		extends
		GenericHibernateDAO<CourtHearingNegotiations, String, CourtHearingNegotiationsDAO>
		implements CourtHearingNegotiationsDAO {

	private Logger LOG = Logger
			.getLogger(CourtHearingNegotiationsDAOHibernate.class);

	protected CourtHearingNegotiationsDAOHibernate() {

	}

	// find OPEN court hearing negotiation by caseRecordUuid
	public CourtHearingNegotiations findCourtHearingNegotiationsByCaseRecordUuid(
			String caseRecordUuid) {
		Query q = getSession()
				.createQuery(
						"from CourtHearingNegotiations chn where chn.status.code = 1 and chn.caseRecord.uuid =? ");
		q.setString(0, caseRecordUuid);
		List result = q.list();
		if (result.isEmpty())
			return null;
		else
			return (CourtHearingNegotiations) result.get(0);
	}
	

	public void updateCourtHearingNegotiationStausToAccepted(CourtHearingNegotiations chn) {
		
		CourtHearingNegotiationStatusDAO statusDAO =  DAOFactory.DEFAULT.getCourtHearingNegotiationStatusDAO(); 
		//CourtHearingNegotiationStatus status = statusDAO.findById(new Integer(3), false);
		CourtHearingNegotiationStatus status = statusDAO.findById(new Integer(3));
		chn.setStatus(status);
		this.makePersistent(chn);
		
	}

	public void updateCourtHearingNegotiationStausToRejected(CourtHearingNegotiations chn) {
		CourtHearingNegotiationStatusDAO statusDAO =  DAOFactory.DEFAULT.getCourtHearingNegotiationStatusDAO(); 
		//CourtHearingNegotiationStatus status = statusDAO.findById(new Integer(2), false);
		CourtHearingNegotiationStatus status = statusDAO.findById(new Integer(3));
		chn.setStatus(status);
		this.makePersistent(chn);
		
	}
	
	

	
		
	

}
